package com.kb.mapper.sqlServer.kbidm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kb.dto.crm.YLCrmInfo;
import com.kb.entity.crm.Customer;
import com.kb.entity.crm.LinkManOfCustomer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface KbContactsMapper extends BaseMapper<LinkManOfCustomer> {
    @Select("<script>" +
            "SELECT Customer.* " +
            "FROM [dbo].[Customer] " +
            "LEFT JOIN LinkManOfCustomer ON LinkManOfCustomer.CustomerId = Customer.RecId " +
            "<where>" +
            "<if test='ylCrmInfo.phone != null'>" +
            "OR LinkManOfCustomer.Tel LIKE CONCAT('%', #{ylCrmInfo.phone}, '%') " +
            "OR LinkManOfCustomer.Mobile LIKE CONCAT('%', #{ylCrmInfo.phone}, '%') " +
            "</if>" +
            "<if test='ylCrmInfo.email != null'>" +
            "OR LinkManOfCustomer.email LIKE CONCAT('%', #{ylCrmInfo.email}, '%') " +
            "</if>" +
            "<if test='ylCrmInfo.customerName != null'>" +
            "OR LinkManOfCustomer.LinkManName LIKE CONCAT('%', #{ylCrmInfo.customerName}, '%') " +
            "</if>" +
            "<if test='ylCrmInfo.userName != null'>" +
            "OR LinkManOfCustomer.LinkManName LIKE CONCAT('%', #{ylCrmInfo.userName}, '%') " +
            "</if>" +
            "</where>" +
            "</script>")
    List<Customer> getCrmCustomer(@Param("ylCrmInfo") YLCrmInfo ylCrmInfo);

}
